package zgrjb.snbq.teach_platform.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import zgrjb.snbq.teach_platform.component.OSSComponent;
import zgrjb.snbq.teach_platform.dto.model.CommentDO;
import zgrjb.snbq.teach_platform.dto.req.AddAdviceRequest;
import zgrjb.snbq.teach_platform.dto.req.AddCommentRequest;
import zgrjb.snbq.teach_platform.dto.req.AddTopicRequest;
import zgrjb.snbq.teach_platform.dto.req.QueryTopicRequest;
import zgrjb.snbq.teach_platform.service.*;
import zgrjb.snbq.teach_platform.util.JsonData;

@RestController
@RequestMapping("/api/v1/stu")
public class StudentController {

    @Autowired
    private ClassService classService;

    @Autowired
    private TopicService topicService;

    @Autowired
    private AttendService attendService;

    @Autowired
    private OSSComponent ossComponent;

    @Autowired
    private FileService fileService;

    @Autowired
    private AdviceService adviceService;

    @Autowired
    private CommentService commentService;



    /**
     * 学生申请加入班级
     * @return
     */
    @GetMapping("add")
    public JsonData add(@RequestParam(value = "classId") Long classId){
        JsonData jsonData = attendService.add(classId);
        return jsonData;
    }

    /**
     * 学生获取班级信息
     * @param id
     * @return
     */
    @GetMapping("info/{id}")
    public JsonData info(@PathVariable("id")Long id){
        JsonData jsonData    = classService.info(id);
        return jsonData;
    }

    /**
     * 统一上传文件接口
     * @param file
     * @return
     */
    @PostMapping("upload_file")
    public JsonData uploadFile(@RequestPart("file") MultipartFile file){
        JsonData jsonData = ossComponent.uploadFile(file);
        return jsonData;
    }


    /**
     * 获取班级文件列表
     * @param classId
     * @return
     */
    @GetMapping("file/{class_id}")
    public JsonData getFile(@PathVariable("class_id") Long classId){
        JsonData jsonData = fileService.list(classId);
        return jsonData;
    }


    /**
     * 添加建议
     * @param addAdviceRequest
     * @return
     */
    @PostMapping("add_advice")
    public JsonData getAddresses(@RequestBody AddAdviceRequest addAdviceRequest){
        JsonData jsonData = adviceService.addAdvice(addAdviceRequest);
        return jsonData;
    }

    /**
     * 获取自己某堂课的所有评价
     * @param classId
     * @return
     */
    @GetMapping("list_advice")
    public JsonData getListAdvice(@RequestParam("class_id")Long classId){
        JsonData jsonData = adviceService.list(classId);
        return jsonData;
    }

    /**
     * 添加话题
     * @param request
     * @return
     */
    @PostMapping("add_topic")
    public JsonData getAddTopics(@RequestBody AddTopicRequest request){
        JsonData jsonData = topicService.add(request);
        return jsonData;
    }

    /**
     * 分页获取某堂课所有话题
     * @param
     * @return
     */
    @GetMapping("list_topic")
    public JsonData ListTopic(@RequestBody QueryTopicRequest request){
        JsonData jsonData = topicService.list(request);
        return jsonData;
    }

    /**
     * 删除话题
     * @param topicId
     * @return
     */
    @GetMapping("del_topic")
    public JsonData delTopic(@RequestParam("topic_id")Long topicId){
        JsonData jsonData = topicService.del(topicId);
        return jsonData;
    }

    /**
     * 点赞话题
     * @param topicId
     * @return
     */
    @GetMapping("good_topic")
    public JsonData goodTopic(@RequestParam("topic_id")Long topicId){
        JsonData jsonData = topicService.goodTopic(topicId);
        return jsonData;
    }
    @GetMapping("list_comment")
    public JsonData listComment(@RequestParam("topic_id")Long topicId,@RequestParam("page")int page,@RequestParam("size")int size){
        JsonData jsonData = commentService.list(topicId,page,size);
        return jsonData;
    }

    @GetMapping("del_comment")
    public JsonData delComment(@RequestParam("comment_id")Long commentId){
        JsonData jsonData = commentService.del(commentId);
        return jsonData;
    }




    /**
     * 添加评论
     * @param commentDO
     * @return
     */
    @PostMapping("add_comment")
    public JsonData addComment(@RequestBody CommentDO commentDO){
        JsonData jsonData = commentService.addComment(commentDO);
        return jsonData;
    }

    /**
     * 点赞评论
     */
    @PostMapping("good_comment")
    public JsonData goodComment(@RequestParam("comment_id")Long commentId){
        JsonData jsonData = commentService.goodComment(commentId);
        return jsonData;
    }

}
